#include "LFPInStream.h"
#include <memory>
CLFPInStream::CLFPInStream()
{
	m_pData   = 0;
	m_nLength = 0;

	m_pCompressData = 0;
	m_nOriginLength = 0;
	m_nCompressRate = -1;
	m_bCompress = false;
}


CLFPInStream::~CLFPInStream()
{

}

char* CLFPInStream::getData()
{
#ifdef _USE_COMPRESS
	return m_pCompressData;
#else
	return m_pData;
#endif
}

char* CLFPInStream::getUnCompressData()
{
	return m_pData;

}

char* CLFPInStream::getCompressData()
{
	return m_pCompressData;
}

unsigned int  CLFPInStream::getLength()
{
#ifdef _USE_COMPRESS
	return m_nLength;
#else
	return m_nOriginLength;
#endif
}



int CLFPInStream::compressData()
{
#ifdef _USE_COMPRESS
	if ( 0 !=  m_pData && 0 == m_pCompressData )
	{
		m_nLength = m_nOriginLength * 2 + 12;
		m_pCompressData = new char[m_nLength];
		memset( m_pCompressData, 0, m_nOriginLength);

		int nRet = compress( (Bytef*)m_pCompressData,(uLongf *)&m_nLength,(Bytef*)m_pData,m_nOriginLength);
		return nRet;
	}
#endif
	return -1;

}

int CLFPInStream::unCompressData()
{
#ifdef _USE_COMPRESS
	if ( 0 ==  m_pData && 0 != m_pCompressData )
	{
		unsigned int destLen = m_nOriginLength;
		m_pData  =  new char[destLen];

		int nRet = uncompress((Bytef*)m_pData,(uLongf *)&destLen,(Bytef*)m_pCompressData,m_nLength);
		return nRet;
	}
#endif
	return -1;
}